package com.chw.admin.scheduling;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.chw.annotation.PermissionSecurity;
import com.chw.common.ServiceData;
import com.chw.utils.LogUtil;
import com.github.pagehelper.PageInfo;
import com.google.gson.Gson;

@Controller
@RequestMapping({ "/scheduling" })
public class ChwSchedulingController {
	private static LogUtil log = LogUtil.newInstance(ChwSchedulingController.class);

	@Autowired
	private IChwSchedulingService chwSchedulingService;

	@RequestMapping(value = { "/find.do" }, method = {
			org.springframework.web.bind.annotation.RequestMethod.POST }, consumes = {
					"*/*" }, produces = { "application/json" })
	@ResponseBody
	@PermissionSecurity(name = "查询", module = "排单管理", btnfunc = "find")
	public ServiceData find(HttpServletRequest request, ChwScheduling chwStorage, Integer currentPage, Integer pageSize)
			throws Exception {
		ServiceData ret = new ServiceData();
		PageInfo<ChwScheduling> chw = this.chwSchedulingService.findEntity(chwStorage, currentPage, pageSize);
		ret.setCode(request, ServiceData.RetCode.Success);
		ret.setBo(chw);
		return ret;
	}

	@RequestMapping(value = { "/getEntityById.do" }, method = {
			org.springframework.web.bind.annotation.RequestMethod.POST }, consumes = {
					"*/*" }, produces = { "application/json" })
	@ResponseBody
	@PermissionSecurity(name = "根据id查询", module = "排单管理", btnfunc = "getEntityById")
	public ServiceData getEntityById(HttpServletRequest request, String id) throws Exception {
		ServiceData ret = new ServiceData();
		ChwScheduling chw = this.chwSchedulingService.getEntityById(id);
		ret.setCode(request, ServiceData.RetCode.Success);
		ret.setBo(chw);
		return ret;
	}

	@RequestMapping(value = { "/save.do" }, method = {
			org.springframework.web.bind.annotation.RequestMethod.POST }, consumes = {
					"*/*" }, produces = { "application/json" })
	@ResponseBody
	@PermissionSecurity(name = "新增", module = "排单管理", btnfunc = "save")
	public ServiceData save(HttpServletRequest request, String param) throws Exception {
		ServiceData ret = new ServiceData();
		Gson gson = new Gson();
		ChwScheduling chwStorage = (ChwScheduling) gson.fromJson(param, ChwScheduling.class);
		int i = this.chwSchedulingService.addEntity(chwStorage);
		ret.setCode(request, ServiceData.RetCode.Success);
		ret.setBo(Integer.valueOf(i));
		return ret;
	}

	@RequestMapping(value = { "/update.do" }, method = {
			org.springframework.web.bind.annotation.RequestMethod.POST }, consumes = {
					"*/*" }, produces = { "application/json" })
	@ResponseBody
	@PermissionSecurity(name = "修改", module = "排单管理", btnfunc = "update")
	public ServiceData update(HttpServletRequest request, String param) throws Exception {
		ServiceData ret = new ServiceData();
		Gson gson = new Gson();
		ChwScheduling chwStorage = (ChwScheduling) gson.fromJson(param, ChwScheduling.class);
		int i = this.chwSchedulingService.updateEntity(chwStorage);
		ret.setCode(request, ServiceData.RetCode.Success);
		ret.setBo(Integer.valueOf(i));
		return ret;
	}

	@RequestMapping(value = { "/delete.do" }, method = {
			org.springframework.web.bind.annotation.RequestMethod.POST }, consumes = {
					"*/*" }, produces = { "application/json" })
	@ResponseBody
	@PermissionSecurity(name = "删除", module = "排单管理", btnfunc = "delete")
	public ServiceData delete(HttpServletRequest request, String id) throws Exception {
		ServiceData ret = new ServiceData();
		int i = this.chwSchedulingService.deleteEntity(id);
		ret.setCode(request, ServiceData.RetCode.Success);
		ret.setBo(Integer.valueOf(i));
		return ret;
	}
}